package stores

import (
	"hi-jvm/instructions/base"
	"hi-jvm/rtda"
)

// 引用 指令码：0x3a
type ASTORE struct{ base.Index8Instruction }
// 指令码：0x4b
type ASTORE_0 struct{ base.NoOperandsInstruction }
// 指令码：0x4c
type ASTORE_1 struct{ base.NoOperandsInstruction }
// 指令码：0x4d
type ASTORE_2 struct{ base.NoOperandsInstruction }
// 指令码：0x4e
type ASTORE_3 struct{ base.NoOperandsInstruction }

func (self *ASTORE) Execute(frame *rtda.Frame) {
	_astore(frame, uint(self.Index))
}

func (self *ASTORE_0) Execute(frame *rtda.Frame) {
	_astore(frame, 0)
}

func (self *ASTORE_1) Execute(frame *rtda.Frame) {
	_astore(frame, 1)
}

func (self *ASTORE_2) Execute(frame *rtda.Frame) {
	_astore(frame, 2)
}

func (self *ASTORE_3) Execute(frame *rtda.Frame) {
	_astore(frame, 3)
}

func _astore(frame *rtda.Frame, index uint) {
	ref := frame.OperandStack.PopRef()
	frame.LocalVars.SetRef(index, ref)
}